// 数组方法分为改变原始数组的方法和不会改变原始数组的方法

// 先来实现会改变原始数组的一些方法
Array.prototype._push = function(...value){
    let argLen = arguments.length;
    let thisLen = this.length;
    for(let i=0; i<argLen; i++){
        this[thisLen+i] = arguments[i];
    }
    return this.length;
}

Array.prototype._pop = function(){
    if(!this.length) return undefined;
    let rb = this[this.length-1];
    this[this.length-1] = null;
    this.length = this.length - 1;
    return rb;
}

Array.prototype._shift = function(){
    if(!this.length) return undefined;
    let rb = this[0];
    for(let i=0; i<this.length-1; i++){
        this[i] = this[i+1];
    }
    this[this.length-1] = null;
    this.length = this.length -1;
    return rb;
}

Array.prototype._unshift = function(){
    let arrLen = arguments.length;
    let thisLen = this.length;
    for(let i=thisLen+arrLen-1; i>=arrLen; i++){
        this[i] = this[i-arrLen];
    }
    for(let i=0; i<arrLen; i++){
        this[i] = arguments[i]
    }
    return this.length;
}


// 不改变原始数组的一些方法
Array.prototype._map = function(callback){
    let rb = [];
    for(let i=0; i<this.length; i++){
        rb.push(callback(this[i]));
    }
    return rb;
}

Array.prototype._join = function(splitStr){
    let arr = this;
    if(arr.length <= 0) return ;
    let rb = arr[0];
    for(let i=1; i<arr.length; i++){
        rb += splitStr + arr[i];
    }
    return rb;
}